package com.scedu.repository;

import com.scedu.domain.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
   public  Employee findByName(String name);
   public List<Employee> findByAgeLessThanAndNameStartingWith(Integer age, String name);
   public List<Employee> findByAgeLessThanAndNameIn(Integer age, List<String> name);

   @Query("select o from Employee o where id =(select max(id) from Employee)")
   public Employee getEmployeebyid();

   @Query("select o from Employee o where o.name like %?1% and o.age<?2")
   public  List<Employee> queryParm(String name,Integer age);

   @Query("select o from Employee o where o.name like %:name% and o.age<:age")
   public  List<Employee> queryParmbyname(@Param("name") String name, @Param("age") Integer age);

   @Query(nativeQuery = true,value = "select count(1) from employee")
   public  long getCount();

   @Modifying
   @Query("update Employee o set o.age=:age where o.id=:id")
   public  void update(@Param("id") Integer id,@Param("age") Integer age);
}
